package com.mysoft.gfyx.marketdevelop.controller;

import com.mysoft.framework.rpc.annotation.PubAction;
import com.mysoft.framework.rpc.annotation.PubService;
import com.mysoft.framework.rpc.contants.RequestPrefix;
import com.mysoft.gfyx.common.rpc.opensearch.OpensearchClientFactoryService;
import com.mysoft.gfyx.common.rpc.opensearch.OpensearchClientService;
import com.mysoft.gfyx.common.rpc.opensearch.dto.OpenSearchSingleListResponseDto;
import com.mysoft.gfyx.marketdevelop.controller.dto.CheckSupplierMainDataRequestDto;
import com.mysoft.gfyx.marketdevelop.controller.dto.GetDataByCreditCodeDto;
import com.mysoft.gfyx.marketdevelop.controller.dto.GetDetailDataRequestDto;
import com.mysoft.gfyx.marketdevelop.controller.dto.CheckSupplierMemberRequestDto;
import com.mysoft.gfyx.marketdevelop.mip.dto.CheckSupplierMainDataResponseDto;
import com.mysoft.gfyx.common.rpc.opensearch.dto.SearchSupplierRequestDto;
import com.mysoft.gfyx.marketdevelop.service.SupplierService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@PubService(value = "/supplierDataApi", prefix = RequestPrefix.API)
@Tag(name = "工程单位资料-API")
public class SupplierDataApiController {

    @Autowired
    private SupplierService supplierService;

    @Autowired
    private OpensearchClientFactoryService opensearchClientFactoryService;

    @PubAction(value = "/getSupplierMainData", method = RequestMethod.POST)
    public Object getSupplierMainData(@RequestBody GetDataByCreditCodeDto dto) {
        return supplierService.getSupplierMainData(dto.getOrganizing_code());
    }

    @PubAction(value = "/checkSupplierMainData", method = RequestMethod.POST)
    public List<CheckSupplierMainDataResponseDto> checkSupplierMainData(@RequestBody CheckSupplierMainDataRequestDto dto) {
        return supplierService.getSupplierMainDataMultiName(dto.getSupplierName());
    }

    @PubAction(value = "/searchSupplierName", method = RequestMethod.POST)
    public Object searchSupplierName(@RequestBody SearchSupplierRequestDto dto) {
        OpensearchClientService service = opensearchClientFactoryService.getOpensearchService();
        OpenSearchSingleListResponseDto res = service.searchSupplierName(dto.getKeyword());
        return res.getData();
    }

    @PubAction(value = "/getSupplierContactMobile", method = RequestMethod.POST)
    public Object getSupplierContactMobile(@RequestBody GetDetailDataRequestDto dto) {
        return supplierService.getSupplierContactMobile(dto.getId());
    }

    @PubAction(value = "/checkSupplierMember", method = RequestMethod.POST)
    public Object checkSupplierMember(@RequestBody CheckSupplierMemberRequestDto dto) throws Exception {
        return supplierService.checkSupplierMember(dto.getCompanyName());
    }
}
